package mule;

import static org.junit.Assert.*;

import java.awt.Color;
import java.util.ArrayList;

import org.junit.Test;

/**
 * Tests various different cases for random events for proper updating of
 * variables as well as if the random event is giving the correct events it
 * should be giving.
 * 
 * @author Kevin
 * 
 */
public class RandomEventTest {

	/**
	 * Tests if random event works correctly in terms of chance and updating
	 * player items.
	 */
	@Test
	public void testRandomOnePlayer() {
		Player player = new Player(1, 1, Color.RED, "test");
		ArrayList arr = new ArrayList();
		arr.add(player);
		Game game = new Game(true, 1, new Map(5, 9), arr, 1);

		// set money to 0 for testing purposes
		player.setMoney(0);

		RandomEvent random = new RandomEvent(player);
		// represents which event occurred.
		int event = random.getRandomEvent();
		// since it is only one player, only good events can occur.
		if (event == 1) {
			assertEquals(11, player.getFood());
			assertEquals(6, player.getEnergy());
		} else if (event == 2) {
			assertEquals(2, player.getOre());
		} else if (event == 3) {
			assertTrue(player.getMoney() > 0);
		} else if (event == 4) {
			assertTrue(player.getMoney() > 0);
		}
	}

	/**
	 * Tests if random event works correctly in terms of chance and updating
	 * player items.
	 */
	@Test
	public void testRandomTwoPlayers() {
		Player player = new Player(1, 1, Color.RED, "test");
		Player player2 = new Player(1, 1, Color.BLUE, "test2");
		ArrayList arr2 = new ArrayList();
		arr2.add(player);
		arr2.add(player2);
		Game game = new Game(true, 1, new Map(5, 9), arr2, 1);

		// set money to 0 for player 1 and make player 2 have more money to
		// experience bad events
		player.setMoney(0);
		player2.setMoney(2000);

		RandomEvent random = new RandomEvent(player);
		// represents which event occurred.
		int event = random.getRandomEvent();
		// since it is player one, only good events can occur.
		if (event == 1) {
			assertEquals(11, player.getFood());
			assertEquals(6, player.getEnergy());
		} else if (event == 2) {
			assertEquals(2, player.getOre());
		} else if (event == 3) {
			assertTrue(player.getMoney() > 0);
		} else if (event == 4) {
			assertTrue(player.getMoney() > 0);
		}

		RandomEvent random2 = new RandomEvent(player2);
		// represents which event occurred.
		int event2 = random2.getRandomEvent();
		// since it is player one, only good events can occur.
		if (event2 == 1) {
			assertEquals(11, player2.getFood());
			assertEquals(6, player2.getEnergy());
		} else if (event2 == 2) {
			assertEquals(2, player2.getOre());
		} else if (event2 == 3) {
			assertTrue(player2.getMoney() > 2000);
		} else if (event2 == 4) {
			assertTrue(player2.getMoney() > 2000);
		} else if (event2 == 5) {
			assertTrue(player2.getMoney() < 2000);
		} else if (event2 == 6) {
			assertTrue(player2.getFood() == 4);
		} else if (event2 == 7) {
			assertTrue(player2.getMoney() < 2000);
		}
	}

	/**
	 * Tests if a bad event does not cause a player to go below zero in food and
	 * money.
	 */
	@Test
	public void testLoseMoneyPlayers() {
		Player player = new Player(1, 1, Color.RED, "test");
		Player player2 = new Player(1, 1, Color.BLUE, "test2");
		ArrayList arr3 = new ArrayList();
		arr3.add(player);
		arr3.add(player2);
		Game game = new Game(true, 1, new Map(5, 9), arr3, 1);

		// set money to 0 for player 1 and make player 2 have 0 food and 1 money
		// for testing purposes.
		player.setMoney(0);
		player2.setMoney(1);
		player2.setFood(0);

		RandomEvent random = new RandomEvent(player);
		// represents which event occurred.
		int event = random.getRandomEvent();
		// since it is player one, only good events can occur.
		if (event == 1) {
			assertEquals(11, player.getFood());
			assertEquals(6, player.getEnergy());
		} else if (event == 2) {
			assertEquals(2, player.getOre());
		} else if (event == 3) {
			assertTrue(player.getMoney() > 0);
		} else if (event == 4) {
			assertTrue(player.getMoney() > 0);
		}

		RandomEvent random2 = new RandomEvent(player2);
		// represents which event occurred.
		int event2 = random2.getRandomEvent();
		// since it is player one, only good events can occur.
		if (event2 == 1) {
			assertEquals(3, player2.getFood());
			assertEquals(6, player2.getEnergy());
		} else if (event2 == 2) {
			assertEquals(2, player2.getOre());
		} else if (event2 == 3) {
			assertTrue(player2.getMoney() > 0);
		} else if (event2 == 4) {
			assertTrue(player2.getMoney() > 0);
		} else if (event2 == 5) {
			assertTrue(player2.getMoney() == 0);
		} else if (event2 == 6) {
			assertTrue(player2.getFood() == 0);
		} else if (event2 == 7) {
			assertTrue(player2.getMoney() == 0);
		}
	}

	/**
	 * Tests random event cases for a full game of 4 players.
	 */
	@Test
	public void testFourPlayers() {
		Player player = new Player(1, 1, Color.RED, "test");
		Player player2 = new Player(1, 1, Color.BLUE, "test2");
		Player player3 = new Player(1, 1, Color.GREEN, "test3");
		Player player4 = new Player(1, 1, Color.CYAN, "test4");
		ArrayList arr4 = new ArrayList();
		arr4.add(player);
		arr4.add(player2);
		arr4.add(player3);
		arr4.add(player4);
		Game game = new Game(true, 1, new Map(5, 9), arr4, 1);

		// set money to 0 for player 1 and make player 2 have 0 food and 1 money
		// for testing purposes.
		player.setMoney(0);
		player2.setMoney(1);
		player3.setMoney(100);
		player4.setMoney(1000);

		RandomEvent random = new RandomEvent(player);
		// represents which event occurred.
		int event = random.getRandomEvent();
		// since it is player one, only good events can occur.
		if (event == 1) {
			assertEquals(11, player.getFood());
			assertEquals(6, player.getEnergy());
		} else if (event == 2) {
			assertTrue(player.getOre() >= 2);
		} else if (event == 3) {
			assertTrue(player.getMoney() > 0);
		} else if (event == 4) {
			assertTrue(player.getMoney() > 0);
		}

		RandomEvent random2 = new RandomEvent(player2);
		// represents which event occurred.
		int event2 = random2.getRandomEvent();
		if (event2 == 1) {
			assertEquals(11, player2.getFood());
			assertEquals(6, player2.getEnergy());
		} else if (event2 == 2) {
			assertEquals(2, player2.getOre());
		} else if (event2 == 3) {
			assertTrue(player2.getMoney() > 1);
		} else if (event2 == 4) {
			assertTrue(player2.getMoney() > 1);
		} else if (event2 == 5) {
			assertTrue(player2.getMoney() == 0);
		} else if (event2 == 6) {
			assertTrue(player2.getFood() == 4);
		} else if (event2 == 7) {
			assertTrue(player2.getMoney() == 0);
		}

		RandomEvent random3 = new RandomEvent(player3);
		// represents which event occurred.
		int event3 = random3.getRandomEvent();
		// since it is player one, only good events can occur.
		if (event3 == 1) {
			assertEquals(11, player3.getFood());
			assertEquals(6, player3.getEnergy());
		} else if (event3 == 2) {
			assertEquals(2, player3.getOre());
		} else if (event3 == 3) {
			assertTrue(player3.getMoney() > 100);
		} else if (event3 == 4) {
			assertTrue(player3.getMoney() > 100);
		} else if (event3 == 5) {
			assertTrue(player3.getMoney() < 100);
		} else if (event3 == 6) {
			assertTrue(player3.getFood() == 4);
		} else if (event3 == 7) {
			assertTrue(player3.getMoney() < 100);
		}

		RandomEvent random4 = new RandomEvent(player4);
		// represents which event occurred.
		int event4 = random4.getRandomEvent();
		// since it is player one, only good events can occur.
		if (event4 == 1) {
			assertEquals(11, player4.getFood());
			assertEquals(6, player4.getEnergy());
		} else if (event4 == 2) {
			assertEquals(2, player4.getOre());
		} else if (event4 == 3) {
			assertTrue(player4.getMoney() > 1000);
		} else if (event4 == 4) {
			assertTrue(player4.getMoney() > 1000);
		} else if (event4 == 5) {
			assertTrue(player4.getMoney() < 1000);
		} else if (event4 == 6) {
			assertTrue(player4.getFood() == 4);
		} else if (event4 == 7) {
			assertTrue(player4.getMoney() < 1000);
		}
	}
}
